1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| #include <bits/stdc++.h> #define rep(i, x, y) for (int i = x; i <= y; i++) #define lowbit(x) ((x) & (-(x))) using namespace std;
const int N = 5e5 + 10, inf = 0x3f3f3f3f; typedef pair<int, int> pii; int n, q, l[N], r[N], C[N], ans[N]; map<pii, int> mp; vector<pii> ve, tmp, query; vector<int> t[N];
pii get_dir(int x, int y) { int gcd = __gcd(abs(x), abs(y)); if (gcd) x /= gcd, y /= gcd; return make_pair(x, y); }
void add(int x, int val) { for (; x <= N; x += lowbit(x)) C[x] += val; }
int get_sum(int x) { int ret = 0; for (; x; x -= lowbit(x)) ret += C[x]; return ret; }
int main() { cin >> n; ve.push_back(make_pair(-1, -1)); rep(i, 1, n) { int x; scanf("%d", &x); rep(j, 1, x) { int a, b; scanf("%d%d", &a, &b); tmp.push_back(make_pair(a, b)); } l[i] = ve.size(); for (int j = 0; j < tmp.size(); j++) ve.push_back(get_dir(tmp[j].first - tmp[(j + 1) % tmp.size()].first, tmp[j].second - tmp[(j + 1) % tmp.size()].second)); tmp.clear(); r[i] = ve.size() - 1; }
scanf("%d", &q); rep(i, 1, q) { int a, b; scanf("%d%d", &a, &b); pii temp = make_pair(l[a], r[b]); query.push_back(temp); t[temp.second].push_back(i - 1); } for (int i = 1; i < ve.size(); i++) { if (mp.count(ve[i])) add(mp[ve[i]], -1); add(i, 1); mp[ve[i]] = i; for (int j = 0; j < t[i].size(); j++) ans[t[i][j]] = get_sum(query[t[i][j]].second) - get_sum(query[t[i][j]].first - 1); } rep(i, 0, q - 1) printf("%d\n", ans[i]); return 0; }
|